package map;

import header.MapHandler;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

// The class where Maps is displayed (actually a JPanel)
public class DrawPanel extends JPanel{

	MapHandler m;// = new MapHandler("testmap.txt", 20);
	int i , j, val;
//	int x, y;
	boolean pSelection, oSelection, wSelection;

    public DrawPanel(String s) {
        m = new MapHandler(s, 20);
        addMouseListener(new arrayListener());
    }
	
	public void setPSelect(boolean i) { pSelection = i; }
	public void setOSelect(boolean i) { oSelection = i; }
	public void setWSelect(boolean i) { wSelection = i; }
	
	public void saveMap() { m.save(); }
	public void reset() {
	}
	public int getPlayerXPos() { return m.getPlayerX(); }
	public int getPlayerYPos() { return m.getPlayerY(); }
	
    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2d = (Graphics2D) g;
        m.draw(g2d);
       // System.out.println(m.mapWidth);
		pSelection = false;
		oSelection = false;
		wSelection = false;
    }

    class arrayListener implements MouseListener {
        public void mouseClicked(MouseEvent e) {
            System.out.println("x: " + e.getY() + " y: " + e.getX());
			i = e.getY() / m.getTileSize();
			j = e.getX() / m.getTileSize();
			System.out.println("pSelection: " + pSelection);
			System.out.println("oSelection: " + oSelection);
			System.out.println("wSelection: " + wSelection);
			if(pSelection)
				val = 2;
			else if (oSelection)
				val = 3;
			else if (wSelection)
				val = 0;
			else
				val = 1;
			System.out.println("val: " + val);
			m.setMap(i, j, val);
			repaint();
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseReleased(MouseEvent e) {
        }
    }

}
